<template>
	<view>
	    <!--#ifdef APP-PLUS-->
	    <view class="lz-status_bar">
	        <view class="lz-top_view"></view>
	    </view>
	    <!--#endif-->
	    <view class="">
	    	<view class="textarea" >
	    		<textarea @input="input($event)"  v-model="content" placeholder="请输入您要反馈的内容(必填)" />
	    	</view>
			<view style="margin-top: 30rpx;margin-left: 30rpx;">
				<u-upload
						:fileList="fileList1"
						@afterRead="afterRead"
						@delete="deletePic"
						name="1"
						multiple
						:maxCount="10"
					></u-upload>
					<view style="font-size: 22rpx;color:red;">*</text><text style="color: #9c9c9c;">支持jpg/png格式图片</text></view>
					
			</view>
			<view  class="btnview">
				<view class="sureButton" @tap="submit()">
					提交
				</view>
			</view>
			
	    </view>
		<!-- 反馈信息 -->
		<!-- <view style="width:90%;margin:0 auto;box-shadow:0 0 8rpx #ddd;border-radius:10rpx;margin-top:30rpx;font-size:28rpx;color:#666">
			<view v-for="(item, index) in list" style="padding:30rpx">
			   <view class="">
			   	   {{item.content}}
			   </view>
			  
			   <view style="background:#f6f6f6;border-radius:10rpx;padding:30rpx;margin-top:20rpx">
			   	<span style="color:#abcdfb">回复：</span>{{item.reply}}
			   </view>
			  <!-- <view style="text-align:right;margin-top:20rpx">
			   	  {{item.createtime}}
			   </view> -->
			<!-- </view>
		</view> --> 
	</view>
	
</template>

<script>
    import {mapState} from 'vuex'
    import uniList from '@/pagesa/components/uni-list/uni-list.vue'
    import uniListItem from '@/pagesa/components/uni-list-item/uni-list-item.vue'
    import Error from '@/core/untils/error/index';

    export default {
        data() {
            return {
				user_info:{},
				content:'',
				list:[],
				fileList1: [],
            }
        },
        mounted() {
        },
        computed: {
            ...mapState(['subject', 'userinfo']), 
        },
        components: { 
        },
        onShow() {
		 
        },
		onLoad(){
			this.feedbackList()
		},
        methods: {
		    input($event){
				
				this.content=$event.detail.value 
			},
			async feedbackList(){
				
				let res = await this.$myHttp.post({
					url: this.$myHttp.urlMap.getFeedbackList,
					data: { 
					},
					needLogin: true
				});
				
				if (res.code === 1) {  
					 this.list=res.data.list
				}
			},
			async submit(){ 
				if(this.content==''&&this.content.length<=10){
					this.$myUtils.$prompt.showToast({
					    icon: 'none',
					    title: '请完善反馈，不能少于10字哦~'
					});
					return
				}
				var that=this
				let res = await this.$myHttp.post({
					url: this.$myHttp.urlMap.doFeedback,
					data: {
						content:this.content, 
					},
					needLogin: true
				});
				
				if (res.code === 1) {  
					uni.showToast({
						title: '提交成功，感谢您的反馈',
						icon:'none',
						duration:3000
					})
					that.content='';
					that.feedbackList()
				}
			},
			/*图片的上传*/
			// 删除图片
						deletePic(event) {
							this[`fileList${event.name}`].splice(event.index, 1)
						},
						// 新增图片
						async afterRead(event) {
							// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
							let lists = [].concat(event.file)
							let fileListLen = this[`fileList${event.name}`].length
							lists.map((item) => {
								this[`fileList${event.name}`].push({
									...item,
									status: 'uploading',
									message: '上传中'
								})
							})
							for (let i = 0; i < lists.length; i++) {
								const result = await this.uploadFilePromise(lists[i].url)
								let item = this[`fileList${event.name}`][fileListLen]
								this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
									status: 'success',
									message: '',
									url: result
								}))
								fileListLen++
							}
						},
						uploadFilePromise(url) {
							return new Promise((resolve, reject) => {
								let a = uni.uploadFile({
									url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
									filePath: url,
									name: 'file',
									formData: {
										user: 'test'
									},
									success: (res) => {
										setTimeout(() => {
											resolve(res.data.data)
										}, 1000)
									}
								});
							})
						},
 
        }
    }
</script>


<style>
	.textarea{
		width:84%;margin:0 auto;
		border:1px solid #ddd;
		border-radius:10rpx;
		height:260rpx;
		font-size:28rpx;
		padding:30rpx;
		margin-top:30rpx;
		/* background:#f6f6f6 */
		
	}
	.btnview{
		border-top: 1px solid #ddd;
		    position: fixed;
		    
		    bottom: 10rpx;
		    width: 100%;
		   
	}
	.sureButton{
		    width: 87%;
		    padding: 0 30rpx;
		    margin: 0 auto;
		    margin-top: 10rpx;
		    height: 80rpx;
		    line-height: 80rpx;
		    border-radius: 50rpx;
		    background: #38cefb;
		    color: #fff;
		    text-align: center;
		
	}
</style>
